package com.joycessh.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.joycessh.dao.ITopicHbmDao;
import com.joycessh.po.TopicPO;
import com.joycessh.util.HibernateUtil;

public class TopicHbmDaoImpl implements ITopicHbmDao {
	
	/**
	 * @author joycessh
	 */
	
	HibernateUtil hbm = new HibernateUtil();
	
	@SuppressWarnings("unchecked")
	public List<TopicPO> findAll(String key) {
		//获得session
		//Session session = hbm.getSession();
		//创建query对象
		//Query query = session.createQuery("from TopicPO");
		//查询 list
		//return query.list();
		
		 //1 获得session  
        @SuppressWarnings("static-access")
		Session session = hbm.getSession();  
        //2 创建query对象   
        Query query = session.createQuery("from TopicPO where title like :key ");  
        //3 设置参数  
        if(key!=null && !"".equals(key.trim())){//页面传条件了  
            query.setString("key", "%"+key+"%");  
        }else{//页面没传条件=>查询所有  
            query.setString("key", "%");  
        }  
        //4 查询 list  
        return query.list();  
		
	}
	

}
